<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache,must-revalidata">
<meta http-equiv="expires" content="0">
<title>添加文章</title>
<meta name="description" content="">
<meta name="keywords" content="">
<base href="<?php echo base_url();?>">
<link href="<?php echo base_url('application/views/css/article.css');?>" rel="stylesheet">

<link type="text/css" rel="stylesheet" href="<?php echo base_url('application/views/themes/default/css/ueditor.min.css');?>">
<script type="text/javascript" charset="utf-8" src="<?php echo base_url('application/views/ueditor.config.js');?>"></script>
<script type="text/javascript" charset="utf-8" src="<?php echo base_url('application/views/ueditor.all.min.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('application/views/lang/zh-cn/zh-cn.js');?>"></script>
</head>
<body>

<div class='main'>

	<div class="form_wrapper">

		<form action="<?php echo site_url('admin/article/insert');?>" method="post">

			<div id='top'>
				<input type="button" name='button' class='btn' value='返回' onclick="history.back()">
				<input type="submit" name='submit_draft' class='btn' value='保存为草稿'>
                <input type="submit" name='submit' class='btn' value='发布'>
				<input type="reset" name='reset' class='btn' value='重写'>
			</div>

			<div id='middle'>
				<input type="text" name='title' class='text' placeholder='还没有标题...' autocomplete='off' style="width:10%;" required>
				<input type="text" name='keyword' class='text' placeholder='还没摘要...' autocomplete='off' required>
				<input list='category' class='text' name='category_id' placeholder='分类' autocomplete='off' style="width:10%;" required onclick="load_category();" >
				<datalist id="category" style='border:0;'></datalist>
			</div>

			<div id='content'>
				<textarea name="content" id="editor"></textarea>
			</div>

		</form>
	
	</div>

</div>
<script type="text/javascript">
    //实例化编辑器   
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    // load category
    function load_category()
    {
    	//创建一个ajax对象
    	var xhr = new XMLHttpRequest();
    	//感知ajax对象的状态信息
    	xhr.onreadystatechange = function(){
    		if(xhr.readyState == 4)
    		{
    			eval("var json_info = "+xhr.responseText);
    			var obj = document.getElementById('category');
    			if(obj.children.length<json_info.length)
    			{
	    			for(var i = 0;i<json_info.length;i++)
	    			{
    					var opt = document.createElement('option');
    					var node = document.createTextNode(json_info[i].name);
    					opt.value = json_info[i].name;
    					opt.appendChild(node);
    					obj.appendChild(opt);
	    			}
    			}

    		}
    	}
    	//创建新http协议
    	var url = '<?php echo site_url('ajax/get_article_category');?>';
    	xhr.open('post',url);
    	//发送请求
    	xhr.send(null);
    }
</script>
</body>
</html>